package middleware

import (
	
	"net/http"
	"time"

	"github.com/zeromicro/go-zero/core/logx"

)

type LoggingMiddleware struct {
}

func NewLoggingMiddleware() *LoggingMiddleware {
	return &LoggingMiddleware{}
}

func (m *LoggingMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()
		
		// 记录请求信息
		logx.Infof("Request: %s %s", r.Method, r.URL.Path)
		
		// 调用下一个处理程序
		next(w, r)
		
		// 记录响应时间和状态
		duration := time.Since(start)
		logx.Infof("Response: %s %s - %v", r.Method, r.URL.Path, duration)
	})
}